package com.uenpay.im.ui.old.activity.publicnumber;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;


/**
 * @author SL
 * @created 2016-1-8 上午0:27:35
 * @copyRight http://www.qiyunxin.com
 */
public class GetPublicNumMenuInvokeItem extends BaseHttpInvokeItem {
	public class GetPublicNumMenuInvokeItemResult extends HttpInvokeResult {
		public ArrayList<PublicNumMenu> arrayList = new ArrayList<PublicNumMenu>();
		public String dataJson = "";
	}

	public GetPublicNumMenuInvokeItemResult getOutput() {
		return (GetPublicNumMenuInvokeItemResult) GetResultObject();
	}

	public GetPublicNumMenuInvokeItem(String custid) {
		String url = APIConfiguration.getBaseUrl()
				+ "PublicNo/PublicNo/publicNoMenu?custid=" + custid + "&" + APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetPublicNumMenuInvokeItemResult result = new GetPublicNumMenuInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		
		JSONObject dataJson = json.optJSONObject("data");
		if(dataJson == null)
			return result;
		result.dataJson = dataJson.toString();
		result.arrayList = SerializerPublicNumMenu.desPublicNumMenus(result.dataJson);
		return result;
	}
	
	
}
